package javbot.command;


import java.awt.AWTException;
import java.awt.event.KeyEvent;

import javbot.GlobalClass;
import javbot.keydata.KeyData.KeyComb;

public class CmdType extends Command {

	final char[] toType;
	final int delay; 
		
	public CmdType(String toType, int delay) throws AWTException {
		super();
		this.toType = toType.toCharArray();
		this.delay = delay;
	}

	public void execute() {
		
		for (int i=0; i<toType.length;i++) {
			int asciiCode;
			KeyComb keyComb = null;
			asciiCode = (int) toType[i];
			try {
				keyComb = GlobalClass.keyData.getVkCodeForChar(asciiCode);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
			if (keyComb.shift) robot.keyPress(KeyEvent.VK_SHIFT);
			robot.keyPress(keyComb.vkCode);
			robot.keyRelease(keyComb.vkCode);
			if (keyComb.shift) robot.keyRelease(KeyEvent.VK_SHIFT);
			robot.delay(delay);
		}
	}	
	
	public String toString() {
		return "Type '" + String.valueOf(toType) + "'";
	}

}
